package com.xk._02算法篇._04recrusion;

/**
 * @description:
 * @author: xu
 * @date: 2022/10/15 23:07
 */
public class TailCall {
    public static void main(String[] args) {
        //new TailCall().test1(5);
        System.out.println(facttorial1(5));
    }

    void test(int n) {
        if (n < 0) return;
        System.out.println("test - " + n);
        test(n-1);
    }
    void test1(int n) {
        if (n < 0) return;
        while (n >= 0) {
            System.out.println("test - " + n);
            n--;
        }
    }



    static int facttorial(int n) {
        if (n <= 1) return n;
        return n * facttorial(n-1);
    }

    static int facttorial1(int n) {
        return facttorial1(n, 1);
    }
    static int facttorial1(int n, int result) {
        if (n <= 1) return result;
        return facttorial1(n-1, n * result);
    }
}

